package com.bjsxt.user.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.common.util.PageInfoUtil;
import com.bjsxt.user.dao.IAdminDao;
import com.bjsxt.user.pojo.AAdmin;
import com.bjsxt.user.service.IService;

@Service("service")
public class IServiceImpl implements IService
{	
	@Resource
	private IAdminDao adminDao;
	@Override
	public JSONObject insertAdmin(AAdmin admin)
	{	
	
		JSONObject json = new JSONObject();
		int rs = adminDao.insert(admin);
		/*String str=null;
		str.toString();*/
		System.out.println("rs------------------"+rs);
		if(rs>0)
		{
			json.put("info", "插入成功");
			json.put("code", 1);
		}else
		{
			json.put("info", "插入失败");
			json.put("code", 0);
		}
		return json;
	}
	@Override
	public AAdmin findOneAdmin(Map<String, Object> condMap)
	{
		AAdmin admin = adminDao.findOne(condMap);
		return admin;
	}
	@Override
	public JSONObject deleteAdmin(AAdmin admin)
	{
		int rs = adminDao.delete(admin);
		JSONObject json = new JSONObject();
		/*String str=null;
		str.toString();*/
		if(rs>0)
		{
			json.put("info", "删除成功");
			json.put("code", 1);
		}else
		{
			json.put("info", "删除失败");
			json.put("code", 0);
		}
		return json;
	}
	@Override
	public JSONObject updateAdmin(AAdmin admin)
	{
		int rs = adminDao.update(admin);
		JSONObject json = new JSONObject();
		/*String str=null;
		str.toString();*/
		if(rs>0)
		{
			json.put("info", "更新成功");
			json.put("code", 1);
		}else
		{
			json.put("info", "更新失败");
			json.put("code", 0);
		}
		return json;
	}
	@Override
	public List<AAdmin> findListAdmin(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		List<AAdmin> list=null;
		if(pageInfoUtil != null)
		{	
			String keyword =(String)condMap.get("keyword");
			if(keyword !=null){
				condMap.put("keyword", "%"+keyword+"%");
			}
			condMap.put("countTotal", "");
			List<AAdmin> adminList = adminDao.findList(condMap);
			int count = adminList.get(0).getId();
			pageInfoUtil.setTotalRecord(count);
			condMap.remove("countTotal");
			condMap.put("pageInfo", "");
			condMap.put("curRecord", pageInfoUtil.getCurrRecord());
			condMap.put("pageSize", pageInfoUtil.getPageSize());
			list= adminDao.findList(condMap);
			return list;
		}else
		{
			 list = adminDao.findList(condMap);
		}
		return list;
	}
}
